package com.xyoto.community.config;

import com.xyoto.community.pojo.Type2PictureInfo;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.HashMap;
import java.util.Map;

/**
 * 图片配置类
 */
@PropertySource(value = "classpath:picture.properties",encoding = "utf-8")
@ConfigurationProperties(prefix = "map")
@Configuration
@Getter
@Setter
public class PictureConfig {

    private Map<Integer, String> type2DirectoryNameMap = new HashMap<>();
    private Map<Integer, String> type2TableNameMap = new HashMap<>();

    /**
     * 根据图片类别获取到该图片类别的数据库表名和oss存储目录名
     * @param type 图片类别
     * @return 数据库表名和oss存储目录名
     */
    public Type2PictureInfo getPictureInfoByType(Integer type){
        String tableName = type2TableNameMap.get(type);
        String directoryName = type2DirectoryNameMap.get(type);
        if (!StringUtils.isEmpty(tableName) && !StringUtils.isEmpty(directoryName)){
            return new Type2PictureInfo(tableName, directoryName);
        }
        return null;
    }

}



